const strFormat = require("../../util/strFormat");
const sql = data => {
  return strFormat(
    "delete from line " + 
    "where id={id} and name='{name}';",
    data
  );
};

const deleteline = (connection, req, res) => {
  connection.query(sql(req.body.data), (err, result) => {
    var data = null;

    if ( err || result.affectedRows === 0 ) {
      if ( err ) console.error(err);
      res.status(200).json({
        status: "fail",
        data: data,
      });
      return;
    } else {
      data = {
        id: req.body.data.id,
        name: req.body.data.name,
      };

      res.status(200).json({
        status: "success",
        data: data,
      });
    }
  });
}

module.exports = deleteline;